package com.briup.demo.dao;
import com.briup.demo.bean.User;
import com.briup.demo.bean.extend.UserExtend;
import org.apache.ibatis.annotations.*;
import java.util.List;

public interface UserMapper {

    @Select("select * from user")
    List<User> selectAll();

    @Insert("insert into user values(null,#{username},#{password},#{telephone},#{gender},#{realname},#{status},#{parentId})")
    void insert(User user);

    @Update("update user set username=#{username},password=#{password},telephone=#{telephone},gender=#{gender},realname=#{realname},status=#{status},parentId=#{parentId} where id=#{id}")
    void update(User user);

    @Delete("delete from user where id=#{id}")
    void delete(Long id);

    @Results({
            @Result(property = "parentId",  column = "parent_id"),
            @Result(property = "roleName",  column = "role_name")
    })
    @Select("select u.*,r.name as role_name from user u left join role r on u.parent_id = p.id")
    List<UserExtend> selectAllWithRole();

}
